package main;

/**
 *
 * @author Ramunas
 */
import java.util.LinkedList;
import javax.swing.table.AbstractTableModel;
import resources.Resource;

public class ResTable extends AbstractTableModel{
    private final int COLUMNS = 4;
    private final int RESOURCE = 0;
    private final int REQUIRED = 1;
    private final int CREATOR = 2;
    private final int USER = 3;
    private LinkedList<Resource> list;
    private String[] columnName = new String[COLUMNS]; 
    
    public ResTable(){
        this.columnName[RESOURCE] = "Resource";
        this.columnName[REQUIRED] = "Required";
        this.columnName[CREATOR] = "Creator";
        this.columnName[USER] = "User";
        this.list = Lists.getResources();
    }
    
    @Override
    public String getColumnName(int index){
        return columnName[index];
    }
    
    @Override
    public int getRowCount() {
        return list.size();
    }

    @Override
    public int getColumnCount() {
        return COLUMNS;
    }

    @Override
    public Object getValueAt(int row, int column) {
        String result;
        switch(column){
            case RESOURCE: result = list.get(row).getName();
                           break;
            case REQUIRED: result = list.get(row).getRequired();
                           break;
            case CREATOR:  result = list.get(row).getCreatorName();
                           break;
            case USER:     result = list.get(row).getUser();
                           break;
            default:       result = "false";
                           break;
        }
        
        return result;
    }

}
